/* =============================================================================
#     FileName: init.c
#         Desc:
#       Author: joseph_lee
#        Email: joseph_lee2633@163.com
#     HomePage:
#      Version: 0.0.1
#   LastChange: 2014-05-21 09:19:14
#      History:
============================================================================= */
#include "s3c24xx.h"
#define WDTCON (*(volatile unsigned int *)0x53000000)
void disable_wdt()
{
	WDTCON=0;
}

void memsetup()
{
	int *p = (unsigned long *)MEM_CTL_BASE, i;
	unsigned long const mem_cfg_val[]={
		0x22011110,      //BWSCON
		0x00000700,     //BANKCON0
		0x00000700,     //BANKCON1
		0x00000700,     //BANKCON2
		0x00000700,     //BANKCON3
		0x00000700,     //BANKCON4
		0x00000700,     //BANKCON5
		0x00018005,     //BANKCON6
		0x00018005,     //BANKCON7
		0x008C07A3,     //REFRESH
		0x000000B1,     //BANKSIZE
		0x00000030,     //MRSRB6
		0x00000030,     //MRSRB7
	};
	for (i = 0; i < 13; i++) {
		p[i]=mem_cfg_val[i];
	}
}

#define S3C2410_MPLL_200MHZ     ((0x5c<<12)|(0x04<<4)|(0x00))
#define S3C2440_MPLL_200MHZ     ((0x5c<<12)|(0x01<<4)|(0x02))
void clock_init(void)
{

	CLKDIVN  = 0x03;            // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1

	/* 如果HDIVN非0，CPU的总线模式应该从“fast bus mode”变为“asynchronous bus mode” */
	__asm__(
			"mrc    p15, 0, r1, c1, c0, 0\n"        /* 读出控制寄存器 */
			"orr    r1, r1, #0xc0000000\n"          /* 设置为“asynchronous bus mode” */
			"mcr    p15, 0, r1, c1, c0, 0\n"        /* 写入控制寄存器 */
	       );

	/* 判断是S3C2410还是S3C2440 */
	if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002))
	{
		MPLLCON = S3C2410_MPLL_200MHZ;  /* 现在，FCLK=200MHz,HCLK=100MHz,PCLK=50MHz */
	}
	else
	{
		MPLLCON = S3C2440_MPLL_200MHZ;  /* 现在，FCLK=200MHz,HCLK=100MHz,PCLK=50MHz */
	}
}
